import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;

import java.util.List;

/**
 * 单选框操作
 */
public class ActionSelenium03 {
    public WebDriver driver;
    //初始化
    public void InitDrive(){
        //驱动配置
//        System.setProperty("webdriver.chrome.driver","D:\\Enviroments\\geckodriver-v0.26.0-win64\\chromedriver.exe");
        System.setProperty("webdriver.edge.marionette","D:\\Enviroments\\geckodriver-v0.26.0-win64\\geckodriver.exe");
        //创建对象
        driver = new EdgeDriver();
        //打开慕课网登录网页
        driver.get("https://www.imooc.com/user/setprofile");
        //网页窗口最大化
        driver.manage().window().maximize();
    }
    //单选框相关方法
    public void radioBox() throws Exception{
        driver.findElement(By.className("pull-right")).click();
        //通过绝对路径定位
        String xpath = "//*[@id=\"profile\"]/div[4]/div/label/input";
        List<WebElement> elements = driver.findElements(By.xpath(xpath));
        System.out.println(elements.size());
        //Thread.sleep(2000);
        for (WebElement radio:elements) {
            boolean flag = radio.isSelected();
            if (flag == false){
                radio.click();
                break;
            }else {
                System.out.println("已选中");

            }
        }
    }
    public static void main(String[] args) throws Exception{
        ActionSelenium03 as = new ActionSelenium03();
        as.InitDrive();
        Thread.sleep(1000);
        as.radioBox();

    }
}
